﻿Imports System.io
Imports Crom.Controls.Docking
Imports System.Windows.Forms
Imports System.Runtime.InteropServices
Imports System.Threading
Imports System.Drawing
Imports bus
Imports dto
Imports DevComponents.DotNetBar
Module Module1
#Region "Load form tobe docking"
    Public Enum themsua
        them = 0
        sua = 1
        Khong = 3
    End Enum
    Enum LOAICA_MODULE
        SÁNG = 1
        CHIỀU = 2
        TỐI = 3
    End Enum
    Public GIOSANG_MODULE As Date = "1/1/1900 6:00:00"
    Public GIOCHIEU_MODULE As Date = "1/1/1900 12:00:00"
    Public GIOTOI_MODULE As Date = "1/1/1900 17:00:00"
    Public GIOKHUA_MODULE As Date = "1/1/1900 23:59:00"
    Public LSchinh As New licensePM("ĐỒ ÁN MÔN HỌC - QUẢN LÝ HỌC SINH", "S", " ", "")
    Public ketnoi As New KetNoiDto
    Public Dtoquyen As New Quyendto
    Public dtonguoidung As New Nguoidungdto
    Public strTQL As String = "Tổng Quản Lý"
    'Sub CreateAccessDatabase(ByVal strDBPath As String)
    '    Dim catNewDB As ADOX.Catalog
    '    catNewDB = New ADOX.Catalog
    '    catNewDB.Create("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath)
    '    catNewDB = Nothing
    'End Sub
    'Public Sub CreateSQLCEdatatable(ByVal strCEDatabaseFilePath As String, ByVal strSqlScriptsFilePath As String)
    '    If System.IO.File.Exists(strCEDatabaseFilePath) Then
    '    End If
    '    Dim strDatabaseSchema As String = File.ReadAllText(strSqlScriptsFilePath)
    '    Dim strConnString As String = "Data Source=" & strCEDatabaseFilePath
    '    Using objCeEngine As New SqlCeEngine(strConnString)
    '        objCeEngine.CreateDatabase()
    '        prvCreateDatabaseSchema(strDatabaseSchema, strConnString)
    '    End Using
    'End Sub
    'Private Sub prvCreateDatabaseSchema(ByVal strDatabaseSchema As String, ByVal strConnString As String)
    '    Using objConn As New SqlCeConnection(strConnString)
    '        Dim arrCommands As String() = strDatabaseSchema.Split(New String() {"go"}, StringSplitOptions.RemoveEmptyEntries)
    '        Dim objCmd As New SqlCeCommand()
    '        objCmd.Connection = objConn
    '        objConn.Open()
    '        For Each strCmd As String In arrCommands
    '            Dim strTrimmedCmd As String = strCmd.Trim()
    '            If Not [String].IsNullOrEmpty(strTrimmedCmd) Then
    '                objCmd.CommandText = strTrimmedCmd
    '                objCmd.ExecuteNonQuery()
    '            End If
    '        Next
    '    End Using
    'End Sub
#Region "Duyệt Menu top"
    'Public Sub duyetMenuTop(ByVal TentabpageSwithcher As RibbonStyle.TabPageSwitcher, ByVal treeview1 As TreeView)
    '    Dim contr As RibbonStyle.TabStripPage
    '    Dim ctr As Control
    '    Dim ctr1 As New Control
    '    Dim rbbt As RibbonStyle.RibbonButton
    '    'Dim treeview1 As New TreeView
    '    Dim node As New TreeNode
    '    Dim node1 As New TreeNode
    '    Dim node2 As New TreeNode
    '    For Each contr In TentabpageSwithcher.Controls
    '        node = treeview1.Nodes.Add(contr.Name, contr.Caption)
    '        For Each ctr In contr.Controls
    '            node1 = node.Nodes.Add(ctr.Name, ctr.Tag)
    '            For Each ctr1 In ctr.Controls
    '                If TypeOf ctr1 Is RibbonStyle.RibbonButton Then
    '                    rbbt = ctr1
    '                    node2 = node1.Nodes.Add(rbbt.Name, rbbt.Text)
    '                    node2.Tag = rbbt.Tag
    '                End If
    '            Next
    '        Next
    '    Next
    'End Sub
#End Region
#Region "Get string rbbt.name"

    'Public Function GetStringName(ByVal TentabpageSwithcher As RibbonStyle.TabPageSwitcher) As String
    'Dim contr As RibbonStyle.TabStripPage
    'Dim ctr As Control
    'Dim ctr1 As New Control
    'Dim rbbt As RibbonStyle.RibbonButton
    'Dim StrName = ""
    '    For Each contr In TentabpageSwithcher.Controls
    '        For Each ctr In contr.Controls
    '            For Each ctr1 In ctr.Controls
    '                If TypeOf ctr1 Is RibbonStyle.RibbonButton Then
    '                    rbbt = ctr1
    'node = treeview1.Nodes.Add(ctr1.Name)
    '                    Return StrName & ".Click"
    '                End If
    '            Next
    '        Next
    '    Next
    '    Return ""
    'End Function


#End Region
    Public Function TaoFileBut(ByVal duongdanFile As String) As String
        Dim file As FileStream
        Dim writer As StreamWriter
        Dim reader As StreamReader
        Try
            file = New FileStream(duongdanFile, FileMode.CreateNew)
            writer = New StreamWriter(file)
            reader = New StreamReader(file)
            While (reader.EndOfStream = True)
                writer.WriteLine("Hello")
            End While
            writer.Close()
            file.Close()
        Catch EX As Exception
            Return (EX.Message)
        End Try
        Return "1"
    End Function
    Public Function DocFileBut(ByVal duongdanFile As String) As String
        Dim file As FileStream
        Dim reader As StreamReader
        Dim a As String = ""
        Try
            file = New FileStream(duongdanFile, FileMode.Open)
            reader = New StreamReader(file)
            While (reader.EndOfStream = False)
                MsgBox(reader.ReadLine)
            End While
            reader.Close()
            file.Close()
        Catch EX As Exception
            Return ""
        End Try
        Return a
    End Function
    Public Sub addTree(ByVal Group As MenuStrip, ByVal treeview1 As TreeView)
        Dim node As New TreeNode
        Dim node1 As New TreeNode
        Dim CTr As New ToolStripMenuItem
        For Each CTr In Group.Items
            node = treeview1.Nodes.Add(CTr.Name, CTr.Text)
            node.Tag = CTr.Tag
            If CTr.DropDownItems.Count > 0 Then
                Dim ctrm As ToolStripItem
                For Each ctrm In CTr.DropDownItems
                    node1 = node.Nodes.Add(ctrm.Name, ctrm.Text)
                    node1.Tag = ctrm.Tag
                Next
            End If
        Next
    End Sub
    Public Function timFormHT(ByVal formName As String) As Form
        Dim a As New Form
        Try
            Dim myAssembly As System.Reflection.Assembly = System.Reflection.Assembly.GetExecutingAssembly()
            Dim types As Type() = myAssembly.GetTypes()
            Dim myType As Type
            For Each myType In types
                If myType.BaseType.FullName = "System.Windows.Forms.Form" Then
                    Dim frmObject As Object = Activator.CreateInstance(myType)
                    DirectCast(frmObject, Form).StartPosition = FormStartPosition.CenterParent
                    If DirectCast(frmObject, Form).Name = formName Then
                        Return DirectCast(frmObject, Form)
                    End If
                End If
            Next
            Return a
        Catch ex As Exception
            MsgBox(ex.ToString)
            Return a
        End Try
    End Function
    Public Sub TimForm_open(ByVal formName As String)
        Dim ProjectName As String = "MetronRELEASECANDIDATE_METRON_RC1_"
        'Dim asm As System.Reflection.Assembly = System.Reflection.Assembly.GetEntryAssembly
        'Dim ProjectName As String = asm.EntryPoint.DeclaringType.Namespace
        Try
            Dim tyOfStringVariable As Type = Type.GetType(ProjectName & "." & formName)
            Dim frmObject As Object = Activator.CreateInstance(tyOfStringVariable)
            DirectCast(frmObject, Form).StartPosition = FormStartPosition.CenterParent
            DirectCast(frmObject, Form).ShowDialog()
        Catch ex As Exception
            ' TODO
        End Try
    End Sub
    Public Function TimForm(ByVal formName As String) As Form
        Dim ProjectName As String = "MetronRELEASECANDIDATE_METRON_RC1_"
        Try
            Dim tyOfStringVariable As Type = Type.GetType(ProjectName & "." & formName)
            Dim frmObject As Object = Activator.CreateInstance(tyOfStringVariable)
            Return DirectCast(frmObject, Form)
        Catch ex As Exception
            Dim frm As New Form
            Return frm
        End Try
    End Function
    Public Sub MakeFormDockingAble(ByVal TenForm As Form, ByVal Tendock As DockContainer, ByVal info As DockableFormInfo, ByVal thongbao As String)
        TenForm.Bounds = New Rectangle(700, 100, 200, 450)
        TenForm.Text = thongbao
        Tendock.DockForm(info, DockStyle.Fill, zDockMode.Outer)
        Tendock.SetHeight(info, 310)
    End Sub
    Public Function imageToByteArray(ByVal imageIn As System.Drawing.Image) As Byte()
        Dim ms As New MemoryStream()
        imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Gif)
        Return ms.ToArray()
    End Function
    Public Function byteArrayToImage(ByVal byteArrayIn As Byte()) As Image
        Dim ms As New MemoryStream(byteArrayIn)
        Dim returnImage As Image = Image.FromStream(ms)
        Return returnImage
    End Function
    Public Sub DuyetMenutop(ByVal treeview As TreeView)
        Dim node As New TreeNode
        Dim node1 As New TreeNode
        Dim node2 As New TreeNode
        For i As Int16 = 0 To MANHINH_CHINH.RibbonControl1.Items.Count - 1
            Try
                Dim cntr As RibbonTabItem = MANHINH_CHINH.RibbonControl1.Items(i)
                node = treeview.Nodes.Add(cntr.Name, cntr.Text)
                For j As Int16 = 0 To cntr.Panel.Controls.Count - 1
                    Dim panel As RibbonBar = cntr.Panel.Controls(j)
                    node1 = node.Nodes.Add(panel.Name, panel.Text)
                    For k As Int16 = 0 To panel.Items.Count - 1
                        Dim con As ButtonItem = panel.Items(k)
                        node2 = node1.Nodes.Add(con.Name, con.Text)
                    Next
                Next
            Catch ex As Exception
            End Try
        Next
    End Sub
    Public Function dich(ByVal ctr As String, ByRef data As DataTable) As String
        Dim str As String = ""
        For i As Integer = 0 To data.Rows.Count - 1
            If data.Rows(i).Item("TenButon") = ctr Then
                str = data.Rows(i).Item("ghichu")
                data.Rows.RemoveAt(i)
                Return str
            End If
        Next
        Return str
    End Function
    'Public Sub Ngonngu(ByVal Con As Control, ByVal tenform As String)
    '    Try
    '        Dim BusChitiet As New QuyenchitietBus(ketnoi)
    '        Dim data As DataTable = BusChitiet.KiemTraCo(0, tenform)
    '        Try
    '            Con.Text = dich(Con.Name, data)
    '        Catch ex As Exception
    '        End Try
    '        Dim ctr As Control
    '        For Each ctr In Con.Controls
    '            If TypeOf ctr Is TextBox Or TypeOf ctr Is ComboBox Or TypeOf ctr Is DateTimePicker Then
    '            ElseIf TypeOf ctr Is ToolStripDropDown Then
    '                Dim TSDD As ToolStripDropDown = ctr
    '                For i As Integer = 0 To TSDD.Items.Count - 1
    '                    TSDD.Items(i).Text = dich(TSDD.Items(i).Name, data)
    '                Next
    '            ElseIf TypeOf ctr Is ToolStrip Then
    '                Dim tool As ToolStrip = ctr
    '                For i As Integer = 0 To tool.Items.Count - 1
    '                    tool.Items(i).Text = dich(tool.Items(i).Name, data)
    '                Next
    '            ElseIf TypeOf ctr Is ContextMenuStrip Then
    '                Dim CMS As ContextMenuStrip = ctr
    '                For i As Integer = 0 To CMS.Items.Count - 1
    '                    CMS.Items(i).Text = dich(CMS.Items(i).Name, data)
    '                Next
    '            ElseIf TypeOf ctr Is StatusStrip Then
    '                Dim STS As StatusStrip = ctr
    '                For i As Integer = 0 To STS.Items.Count - 1
    '                    STS.Items(i).Text = dich(STS.Items(i).Name, data)
    '                Next
    '            ElseIf TypeOf ctr Is System.Windows.Forms.TabControl Then
    '                Dim tabc As System.Windows.Forms.TabControl = ctr
    '                For i As Integer = 0 To tabc.TabPages.Count - 1
    '                    Ngonngu(tabc.TabPages(i), tenform)
    '                Next
    '            ElseIf TypeOf ctr Is DataGridView Then
    '                Dim DGV As DataGridView = ctr
    '                For i As Integer = 0 To DGV.ColumnCount - 1
    '                    DGV.Columns(i).HeaderText = dich(DGV.Columns(i).Name, data)
    '                Next
    '            ElseIf TypeOf ctr Is ListView Then
    '                Dim LV As ListView = ctr
    '                For i As Integer = 0 To LV.Columns.Count - 1
    '                    LV.Columns(i).Text = dich(LV.Columns(i).Name, data)
    '                Next
    '            ElseIf TypeOf ctr Is SplitContainer Then
    '                Dim SPC As SplitContainer = ctr
    '                Ngonngu(SPC.Panel1, tenform)
    '                Ngonngu(SPC.Panel2, tenform)
    '            ElseIf TypeOf ctr Is RibbonControl Then
    '                Dim RC As RibbonControl = ctr
    '                For i As Int16 = 0 To RC.Items.Count - 1
    '                    Try
    '                        Dim cntr As RibbonTabItem = RC.Items(i)
    '                        cntr.Text = dich(cntr.Name, data)
    '                        For j As Int16 = 0 To cntr.Panel.Controls.Count - 1
    '                            Dim panel As RibbonBar = cntr.Panel.Controls(j)
    '                            panel.Text = dich(panel.Name, data)
    '                            For k As Int16 = 0 To panel.Items.Count - 1
    '                                Dim BI As ButtonItem = panel.Items(k)
    '                                BI.Text = dich(Con.Name, data)
    '                            Next
    '                        Next
    '                    Catch ex As Exception
    '                    End Try
    '                Next
    '            Else
    '                Try
    '                    ctr.Text = dich(ctr.Name, data)
    '                Catch ex As Exception
    '                End Try
    '            End If
    '            If ctr.Controls.Count > 0 Then
    '                Ngonngu(ctr, tenform)
    '            End If

    '        Next
    '    Catch ex As Exception
    '    End Try
    'End Sub
    Public Function TENFORM(ByVal TEN As String) As Form
        Select Case TEN

            Case "ManhinhCauHinh"
                Dim A As New ManhinhCauHinh
                Return A
            Case "ManHinhDangNhap"
                Dim A As New ManHinhDangNhap
                Return A
            Case "MANHINH_CHINH"
                Dim A As New MANHINH_CHINH
                Return A
            Case "ManHinhDangKy"
                Dim A As New ManHinhDangKy
                Return A
            Case "ManHinhQuenMatKhau"
                Dim A As New ManHinhQuenMatKhau
                Return A
            Case "ManHinhSuaMatKhau"
                Dim A As New ManHinhSuaMatKhau
                Return A
            Case "ManHinhThongTinNguoidung"
                Dim A As New ManHinhThongTinNguoidung
                Return A
            Case "ManHinhXemNguoidung"
                Dim A As New ManHinhXemNguoidung
                Return A
        End Select
    End Function
    Public Function DocFile(ByVal duongdanFile As String, ByVal ketnoi As KetNoiDto) As String
        Dim file As FileStream
        Dim reader As StreamReader
        Dim busctquyen As New QUYENCHITIETBus(ketnoi)
        Dim a As String = ""
        Try
            file = New FileStream(duongdanFile, FileMode.Open)
            reader = New StreamReader(file)
            While (reader.EndOfStream = False)
                Dim DTOCTQUYEN As New QUYENCHITIETdto()
                a = reader.ReadLine()
                DTOCTQUYEN.TenForm = Left(a, a.IndexOf(vbTab))
                a = Right(a, a.Length - a.IndexOf(vbTab) - 1)
                DTOCTQUYEN.TenButon = Left(a, a.IndexOf(vbTab))
                a = Right(a, a.Length - a.IndexOf(vbTab) - 1)
                DTOCTQUYEN.Trangthai = 1
                a = Right(a, a.Length - a.IndexOf(vbTab) - 1)
                DTOCTQUYEN.Ghichu = a
                busctquyen.Them(DTOCTQUYEN)
            End While
            reader.Close()
            file.Close()
        Catch EX As Exception
            Return ""
        End Try
        Return a
    End Function
    Public Function DOCNgonngu(ByVal ten As String) As String
        Dim STR As String = ""
        Dim CTR As Control = TENFORM(ten)
        If CTR Is Nothing Then Return ""
        STR = DOCNgonngu(CTR, ten)
        Return STR
    End Function
    Public Function DOCNgonngu(ByVal Con As Control, ByVal tenform As String) As String
        Dim STR As String = ""
        Try
            STR = STR & tenform & vbTab & Con.Name & vbTab & Con.Text & ":" & vbNewLine
        Catch ex As Exception
        End Try
        Dim ctr As Control
        For Each ctr In Con.Controls
            If TypeOf ctr Is TextBox Or TypeOf ctr Is ComboBox Or TypeOf ctr Is DateTimePicker Then
            ElseIf TypeOf ctr Is ToolStripDropDown Then
                Dim TSDD As ToolStripDropDown = ctr
                For i As Integer = 0 To TSDD.Items.Count - 1
                    STR = STR & tenform & vbTab & TSDD.Items(i).Name & vbTab & TSDD.Items(i).Text & vbNewLine
                Next
            ElseIf TypeOf ctr Is ToolStrip Then
                Dim tool As ToolStrip = ctr
                For i As Integer = 0 To tool.Items.Count - 1
                    STR = STR & tenform & vbTab & tool.Items(i).Name & vbTab & tool.Items(i).Text & vbNewLine
                Next
            ElseIf TypeOf ctr Is ContextMenuStrip Then
                Dim CMS As ContextMenuStrip = ctr
                For i As Integer = 0 To CMS.Items.Count - 1
                    STR = STR & tenform & vbTab & CMS.Items(i).Name & vbTab & CMS.Items(i).Text & vbNewLine
                Next
            ElseIf TypeOf ctr Is StatusStrip Then
                Dim STS As StatusStrip = ctr
                For i As Integer = 0 To STS.Items.Count - 1
                    STR = STR & tenform & vbTab & STS.Items(i).Name & vbTab & STS.Items(i).Text & vbNewLine
                Next
            ElseIf TypeOf ctr Is System.Windows.Forms.TabControl Then
                Dim tabc As System.Windows.Forms.TabControl = ctr
                For i As Integer = 0 To tabc.TabPages.Count - 1
                    STR = STR & DOCNgonngu(tabc.TabPages(i), tenform) & vbNewLine
                Next
            ElseIf TypeOf ctr Is DataGridView Then
                Dim DGV As DataGridView = ctr
                For i As Integer = 0 To DGV.ColumnCount - 1
                    STR = STR & tenform & vbTab & DGV.Columns(i).Name & vbTab & DGV.Columns(i).HeaderText & vbNewLine
                Next
            ElseIf TypeOf ctr Is ListView Then
                Dim LV As ListView = ctr
                For i As Integer = 0 To LV.Columns.Count - 1
                    STR = STR & tenform & vbTab & LV.Columns(i).Name & vbTab & LV.Columns(i).Text & vbNewLine
                Next
            ElseIf TypeOf ctr Is SplitContainer Then
                Dim SPC As SplitContainer = ctr
                STR = STR & DOCNgonngu(SPC.Panel1, tenform) & vbNewLine
                STR = STR & DOCNgonngu(SPC.Panel2, tenform) & vbNewLine
            ElseIf TypeOf ctr Is DevComponents.AdvTree.AdvTree Then
                Dim AT As DevComponents.AdvTree.AdvTree = ctr
                For I As Integer = 0 To AT.Columns.Count - 1
                    STR = STR & tenform & vbTab & AT.Columns(I).Name & vbTab & AT.Columns(I).Text & vbNewLine
                Next
            ElseIf TypeOf ctr Is RibbonControl Then
                Dim RC As RibbonControl = ctr
                For i As Int16 = 0 To RC.Items.Count - 1
                    Try
                        Dim cntr As RibbonTabItem = RC.Items(i)
                        STR = STR & tenform & vbTab & cntr.Name & vbTab & cntr.Text & vbNewLine
                        For j As Int16 = 0 To cntr.Panel.Controls.Count - 1
                            Dim panel As RibbonBar = cntr.Panel.Controls(j)
                            STR = STR & tenform & vbTab & panel.Name & vbTab & panel.Text & vbNewLine
                            For k As Int16 = 0 To panel.Items.Count - 1
                                Dim BI As ButtonItem = panel.Items(k)
                                STR = STR & tenform & vbTab & BI.Name & vbTab & BI.Text & vbNewLine
                            Next
                        Next
                    Catch ex As Exception
                    End Try
                Next
            Else
                Try
                    STR = STR & tenform & vbTab & ctr.Name & vbTab & ctr.Text & vbNewLine
                Catch ex As Exception
                End Try
            End If
            If ctr.Controls.Count > 0 Then
                STR = STR & DOCNgonngu(ctr, tenform) & vbNewLine
            End If
        Next
        Return STR
    End Function

    Public Sub XEM_Ngonngu(ByVal Con As Control, ByVal tenCONTROL As String, ByVal TIENGANH As String)
        If TIENGANH = "" Or tenCONTROL = "" Then Exit Sub
        Dim ctr As Control
        For Each ctr In Con.Controls
            If TypeOf ctr Is TextBox Or TypeOf ctr Is ComboBox Or TypeOf ctr Is DateTimePicker Then
            ElseIf TypeOf ctr Is Label Then
                If ctr.Name = tenCONTROL Then
                    If IsNumeric(ctr.Tag) = False Then ctr.Tag = ctr.Text
                    ctr.Text = TIENGANH
                End If
            ElseIf TypeOf ctr Is SplitContainer Then
                Dim SPC As SplitContainer = ctr
                XEM_Ngonngu(SPC.Panel1, tenCONTROL, TIENGANH)
                XEM_Ngonngu(SPC.Panel2, tenCONTROL, TIENGANH)
            ElseIf TypeOf ctr Is System.Windows.Forms.TabControl Then
                Dim tabc As System.Windows.Forms.TabControl = ctr
                For i As Integer = 0 To tabc.TabPages.Count - 1
                    XEM_Ngonngu(tabc.TabPages(i), tenCONTROL, TIENGANH)
                Next
            ElseIf TypeOf ctr Is ToolStripDropDown Then
                Dim TSDD As ToolStripDropDown = ctr
                For i As Integer = 0 To TSDD.Items.Count - 1
                    If TSDD.Items(i).Name = tenCONTROL Then
                        If IsNumeric(TSDD.Items(i).Tag) = False Then TSDD.Items(i).Tag = TSDD.Items(i).Text
                        TSDD.Items(i).Text = TIENGANH
                    End If
                Next
            ElseIf TypeOf ctr Is ToolStrip Then
                Dim tool As ToolStrip = ctr
                For i As Integer = 0 To tool.Items.Count - 1
                    If tool.Items(i).Name = tenCONTROL Then
                        If IsNumeric(tool.Items(i).Tag) = False Then tool.Items(i).Tag = tool.Items(i).Text
                        tool.Items(i).Text = TIENGANH
                    End If
                Next
            ElseIf TypeOf ctr Is ContextMenuStrip Then
                Dim CMS As ContextMenuStrip = ctr
                For i As Integer = 0 To CMS.Items.Count - 1
                    If CMS.Items(i).Name = tenCONTROL Then
                        If IsNumeric(CMS.Items(i).Tag) = False Then CMS.Items(i).Tag = CMS.Items(i).Text
                        CMS.Items(i).Text = TIENGANH
                    End If
                Next
            ElseIf TypeOf ctr Is StatusStrip Then
                Dim STS As StatusStrip = ctr
                For i As Integer = 0 To STS.Items.Count - 1
                    If STS.Items(i).Name = tenCONTROL Then
                        If IsNumeric(STS.Items(i).Tag) = False Then STS.Items(i).Tag = STS.Items(i).Text
                        STS.Items(i).Text = TIENGANH
                    End If
                Next
            ElseIf TypeOf ctr Is DataGridView Then
                Dim DGV As DataGridView = ctr
                For i As Integer = 0 To DGV.ColumnCount - 1
                    If DGV.Columns(i).Name = tenCONTROL Then
                        If IsNumeric(DGV.Columns(i).Tag) = False Then DGV.Columns(i).Tag = DGV.Columns(i).HeaderText
                        DGV.Columns(i).HeaderText = TIENGANH
                    End If
                Next
            ElseIf TypeOf ctr Is ListView Then
                Dim LV As ListView = ctr
                For i As Integer = 0 To LV.Columns.Count - 1
                    If LV.Columns(i).Name = tenCONTROL Then
                        If IsNumeric(LV.Columns(i).Tag) = False Then LV.Columns(i).Tag = LV.Columns(i).Text
                        LV.Columns(i).Text = TIENGANH
                    End If
                Next
            ElseIf TypeOf ctr Is DevComponents.AdvTree.AdvTree Then
                Dim AT As DevComponents.AdvTree.AdvTree = ctr
                For I As Integer = 0 To AT.Columns.Count - 1
                    If AT.Columns(I).Name = tenCONTROL Then
                        If IsNumeric(AT.Columns(I).Tag) = False Then AT.Columns(I).Tag = AT.Columns(I).Text
                        AT.Columns(I).Text = TIENGANH
                    End If
                Next
            ElseIf TypeOf ctr Is RibbonControl Then
                Dim RC As RibbonControl = ctr
                For i As Int16 = 0 To RC.Items.Count - 1
                    Try
                        Dim cntr As RibbonTabItem = RC.Items(i)
                        If cntr.Name = tenCONTROL Then
                            If IsNumeric(cntr.Tag) = False Then cntr.Tag = cntr.Text
                            cntr.Text = TIENGANH
                        End If
                        For j As Int16 = 0 To cntr.Panel.Controls.Count - 1
                            Dim panel As RibbonBar = cntr.Panel.Controls(j)
                            If panel.Name = tenCONTROL Then
                                If IsNumeric(panel.Tag) = False Then panel.Tag = panel.Text
                                panel.Text = TIENGANH
                            End If
                            For k As Int16 = 0 To panel.Items.Count - 1
                                Dim BI As ButtonItem = panel.Items(k)
                                If BI.Name = tenCONTROL Then
                                    If IsNumeric(BI.Tag) = False Then BI.Tag = BI.Text
                                    BI.Text = TIENGANH
                                End If
                            Next
                        Next
                    Catch ex As Exception
                    End Try
                Next
            Else
                Try
                    If ctr.Name = tenCONTROL Then
                        If IsNumeric(ctr.Tag) = False Then ctr.Tag = ctr.Text
                        ctr.Text = TIENGANH
                    End If
                Catch ex As Exception
                End Try
            End If
            If ctr.Controls.Count > 0 Then
                XEM_Ngonngu(ctr, tenCONTROL, TIENGANH)
            End If
        Next
    End Sub
    Public Sub XEM_Ngonngu_TIENGVIET(ByVal Con As Control)
        Dim ctr As Control
        For Each ctr In Con.Controls
            If TypeOf ctr Is TextBox Or TypeOf ctr Is ComboBox Or TypeOf ctr Is DateTimePicker Then
            ElseIf TypeOf ctr Is ToolStripDropDown Then
                Dim TSDD As ToolStripDropDown = ctr
                For i As Integer = 0 To TSDD.Items.Count - 1
                    If IsNumeric(TSDD.Items(i).Tag) = False Then
                        TSDD.Items(i).Text = TSDD.Items(i).Tag
                    End If
                Next
            ElseIf TypeOf ctr Is ToolStrip Then
                Dim tool As ToolStrip = ctr
                For i As Integer = 0 To tool.Items.Count - 1
                    If IsNumeric(tool.Items(i).Tag) = False Then
                        tool.Items(i).Text = tool.Items(i).Tag
                    End If
                Next
            ElseIf TypeOf ctr Is ContextMenuStrip Then
                Dim CMS As ContextMenuStrip = ctr
                For i As Integer = 0 To CMS.Items.Count - 1
                    If IsNumeric(CMS.Items(i).Tag) = False Then
                        CMS.Items(i).Text = CMS.Items(i).Tag
                    End If
                Next
            ElseIf TypeOf ctr Is StatusStrip Then
                Dim STS As StatusStrip = ctr
                For i As Integer = 0 To STS.Items.Count - 1
                    If IsNumeric(STS.Items(i).Tag) = False Then
                        STS.Items(i).Text = STS.Items(i).Tag
                    End If
                Next
            ElseIf TypeOf ctr Is System.Windows.Forms.TabControl Then
                Dim tabc As System.Windows.Forms.TabControl = ctr
                For i As Integer = 0 To tabc.TabPages.Count - 1
                    XEM_Ngonngu_TIENGVIET(tabc.TabPages(i))
                Next
            ElseIf TypeOf ctr Is DataGridView Then
                Dim DGV As DataGridView = ctr
                For i As Integer = 0 To DGV.ColumnCount - 1
                    If IsNumeric(DGV.Columns(i).Tag) = False Then
                        DGV.Columns(i).HeaderText = DGV.Columns(i).Tag
                    End If
                Next
            ElseIf TypeOf ctr Is ListView Then
                Dim LV As ListView = ctr
                For i As Integer = 0 To LV.Columns.Count - 1
                    If IsNumeric(LV.Columns(i).Tag) = False Then
                        LV.Columns(i).Text = LV.Columns(i).Tag
                    End If
                Next
            ElseIf TypeOf ctr Is SplitContainer Then
                Dim SPC As SplitContainer = ctr
                XEM_Ngonngu_TIENGVIET(SPC.Panel1)
                XEM_Ngonngu_TIENGVIET(SPC.Panel2)
            ElseIf TypeOf ctr Is DevComponents.AdvTree.AdvTree Then
                Dim AT As DevComponents.AdvTree.AdvTree = ctr
                For I As Integer = 0 To AT.Columns.Count - 1
                    If IsNumeric(AT.Columns(I).Tag) = False Then
                        AT.Columns(I).Text = AT.Columns(I).Tag
                    End If
                Next
            ElseIf TypeOf ctr Is RibbonControl Then
                Dim RC As RibbonControl = ctr
                For i As Int16 = 0 To RC.Items.Count - 1
                    Try
                        Dim cntr As RibbonTabItem = RC.Items(i)
                        If IsNumeric(cntr.Tag) = False Then
                            cntr.Text = cntr.Tag
                        End If
                        For j As Int16 = 0 To cntr.Panel.Controls.Count - 1
                            Dim panel As RibbonBar = cntr.Panel.Controls(j)
                            If IsNumeric(panel.Tag) = False Then
                                panel.Text = panel.Tag
                            End If
                            For k As Int16 = 0 To panel.Items.Count - 1
                                Dim BI As ButtonItem = panel.Items(k)
                                If IsNumeric(BI.Tag) = False Then
                                    BI.Text = BI.Tag
                                End If
                            Next
                        Next
                    Catch ex As Exception
                    End Try
                Next
            Else
                Try
                    If IsNumeric(ctr.Tag) = False Then
                        ctr.Text = ctr.Tag
                    End If
                Catch ex As Exception
                End Try
            End If
            If ctr.Controls.Count > 0 Then
                XEM_Ngonngu_TIENGVIET(ctr)
            End If
        Next
    End Sub
    Public Sub DICHTIENGANH(ByVal tenform As Form, ByVal ketnoi As KetNoiDto)
        If LSchinh.ENGLISH Then
            Dim BusQuyenchitiet As New QUYENCHITIETBus(ketnoi)
            Dim DATAT As DataTable = BusQuyenchitiet.LayBangTableTheoQuyen(0, tenform.Name)
            For I As Integer = 0 To DATAT.Rows.Count - 1
                XEM_Ngonngu(tenform, DATAT.Rows(I)("TenButon"), DATAT.Rows(I)("Ghichu"))
            Next
        End If
    End Sub
#End Region
End Module
